package top.canyue.eca_manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.canyue.eca_manager.bean.Result;
import top.canyue.eca_manager.service.TodoService;

/**
 * 待办相关接口
 *
 * @author Canyue
 * CREATE BY 2024/05/08
 */

@RestController
@RequestMapping(value = "/api/Todo")
public class TodoController {
    @Autowired
    private TodoService todoService;

    /**
     * 基于ID得到代办的详细详细
     *
     * @param id 代办ID
     * @return 代办详情
     */
    @RequestMapping(value = "/findById", method = RequestMethod.GET)
    public Result findById(@RequestParam String id) {
        return todoService.findById(id);
    }

    /**
     * 基于用户ID，得到该用户的所有未完成且未过期的代办
     *
     * @param userId 用户ID
     * @return 所有未完成且未过期的代办
     */
    @RequestMapping(value = "/findByUserId", method = RequestMethod.GET)
    public Result findByUserId(@RequestParam String userId) {
        return todoService.findByUserId(userId);
    }

    /**
     * 为一个用户添加代办
     *
     * @param userId  用户ID
     * @param event   代办事件描述(不大于15个字符)
     * @param endDate 事件结束日期(精确到天，时间会被丢弃)
     * @return 添加结果
     */
    @RequestMapping(value = "/addEvent", method = RequestMethod.POST)
    public Result addEvent(@RequestParam String userId, String event, long endDate) {
        return todoService.addEvent(userId, event, endDate);
    }

    /**
     * 删除(完成)一个待办事项
     *
     * @param id 代办ID
     * @return 删除结果
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public Result deleteById(@RequestParam String id) {
        return todoService.deleteById(id);
    }


}
